﻿using OpenQA.Selenium;
using System.Net;

namespace 天离安全_天擎.Tl_SerVices
{
    /// <summary>
    /// 检查代理服务
    /// </summary>
    public class CheckProxy_Services
    {
        /// <summary>
        /// 检查代理
        /// </summary>
        /// <returns></returns>
        public async Task<List<string>> CheckProxyAsync()
        {
            string proxy = $"{Tl_Api.CrawlerScan_Api.Socks5Proxy_IP}:{Tl_Api.CrawlerScan_Api.Socks5Proxy_Port}";
            try
            {
                // 创建一个 HTTP 请求，使用 SOCKS5 代理进行连接
                var handler = new HttpClientHandler
                {
                    Proxy = new WebProxy(proxy),
                    UseProxy = true,
                };

                using (var client = new HttpClient(handler))
                {
                    client.Timeout = TimeSpan.FromSeconds(5); // 设置超时
                    var response = await client.GetAsync("https://www.baidu.com");
                    Tl_Api.CrawlerScan_Api.Scan_Info.Append(response.ToString() + "\r\n");
                    
                }
            }
            catch (Exception ex)
            {
                Tl_Api.CrawlerScan_Api.Scan_Error.Append(ex.ToString() + "\r\n");
            }
            return new List<string>();
        }
    }
}
